package net.homeip.mmhg.dao;

import java.util.Collection;

import net.homeip.mmhg.domain.Notification;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
/**
 * Hibernate implementation of <code>NotificationDao</code>.
 */
public class NotificationDaoImpl implements NotificationDao {

	private HibernateTemplate template;

	@Autowired
	public void setHibernateTemplate(SessionFactory sessionFactory) {
		this.template = new HibernateTemplate(sessionFactory);
	}
	
	@Override
	@Transactional(readOnly = true)
	public Notification getNotification(int id) {
		return (Notification) template.get(Notification.class, id);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public Collection<Notification> getNotifications() {
		return template.findByCriteria(DetachedCriteria.forClass(Notification.class));
	}
}
